var jsonList = {};
var page = 1;
var rows = 10;
$(function (){
    //获取专题列表
    $(document).on("click",".zt_wz",function (){
        var id =  $(this).attr("data-id");
        var name = $(this).attr("data-title");
        localStorage.setItem("zt_name",name);
        window.location.href = "./ztgx_ck.html?ztid=" + id;
    })
    //获取频道列表
    var jsonl = {};
    var result = JSON.stringify(jsonl);
    $.ajax({
        url: baseNews + "/api/data/channel/list?page=1&rows=200",
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res, 6666);
            if (res.code == 0) {
                var obj = $(".pd_list");
                $(res.data.list).each(function (index, key) {
                    obj.append("<option value='" + key.id + "'>" + key.cname + "</option>");
                })
            }
        }
    })
    //搜索
    $(".zt_state").change(function () {
        jsonList.state  = $(this).val();
    })
    $(".pd_list").change(function () {
        jsonList.cid = $(this).val();
    })
    $(".search_btn").click("on",function (){
        var zt_id = $(".zt_id").val();//专题id
        var zt_name = $(".zt_name").val();//专题name
        if (zt_id!=""){
            jsonList.id = zt_id;
        }
        if (zt_name != "") {
            jsonList.id = zt_name;
        }
        getList();

    })

})
getList();
function getList() {
    var result = JSON.stringify(jsonList);
    $.ajax({
        url: baseNews + "/api/data/update/special/list?page=" + page + "&rows=" + rows,
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res, 666);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList();
                    }
                })
                $(".zt_list").empty();
                $(list).each(function (index, key) {
                    var state = key.state;
                    var newState = "";
                    if (state == 1) {
                        newState = "待审核";
                    }
                    if (state == 2) {
                        newState = "待发布";
                    }
                    if (state == 3) {
                        newState = "已发布";
                    }
                    if (state == 10) {
                        newState = "有更新";
                    }
                    if (state == -1) {
                        newState = "审核失败";
                    }
                    if (state == -2) {
                        newState = "撤销发布";
                    }
                    html += `<div class="main">
				<div class="o">${key.id}</div>
				<div class="th">${key.title}</div>
				<div class="t">${newState}</div>
				<div class="o">${key.cname}</div>
				<div class="t">${key.articles}</div>
				<div class="o">${key.top?"是":"否"}</div>
				<div class="t">${key.click}</div>
				<div class="t">${key.follow}</div>
				<div class="t">${key.collect}</div>
				<div class="t">${key.pass}</div>
				<div class="t">${key.comment}</div>
				<div class="t">${key.heating}</div>
				<div class="t">${key.cooling}</div>
				<div class="o">${key.hot}</div>
				<div class="t">${key.username}</div>
				<div class="th">${key.createtime}</div>
				<div class="th">${key.updatetime}</div>
				<div class="th">${key.atime}</div>
                <div class="th">${key.rtime}</div>
                <div class="o"><span class="zt_wz" data-id="${key.id}" data-title="${key.title}">查看</span></div>
			</div>`;
                })
                $(".zt_list").append(html);
            }
        }
    })
    //分页
}